package cn.sciento.farm.devicemanager.gateway.lorawan.grpc;

import io.grpc.CallCredentials;
import io.grpc.Metadata;

import java.util.concurrent.Executor;

/**
 * @author wumu
 * @version V1.0
 * @date 9/14/18
 * @time 3:41 PM
 */
public class JwtCallCredential extends CallCredentials {
    private  String jwt;

    public JwtCallCredential(String jwt) {
        this.jwt = jwt;
    }



    @Override
    public void applyRequestMetadata(RequestInfo requestInfo, Executor appExecutor, MetadataApplier applier) {
        Metadata headers = new Metadata();
        Metadata.Key<String> jwtKey = Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER);
        headers.put(jwtKey, jwt);
        applier.apply(headers);
    }

    @Override
    public void thisUsesUnstableApi() {
    }
}
